@extends('layout.app')
@section('title','Отчеты по фильтру')
@section('content')
    <a href="{{ route('reports.add') }}" class="bg-blue-600 text-white rounded-[5px] p-[15px] inline-block mb-[50px]">
        Добавить отчет
    </a>
   <div>
       <form action="{{ route('reports__filter') }}" method="POST" class="grid grid-cols-3 gap-[30px]" >
           @csrf
            @method('POST')

           <select name="center">
               <option value="">Выбрать центр</option>
               @foreach ($centers as $center)
                   <option value="{{ $center->id }}" @selected(old('center') == $center->id)>{{ $center->name }}</option>
               @endforeach
           </select>
{{--           <select>--}}
{{--               <option value="">Выбрать регион</option>--}}
{{--               @foreach ($centers as $center)--}}
{{--                   <option value="{{ $center->id }}">{{ $center->name }}</option>--}}
{{--               @endforeach--}}
{{--           </select>--}}


           <select name="instructor">
               <option value="">Выбрать инструктора</option>
               @foreach ($instructors as $instructor)
                   <option value="{{ $instructor->id }}">{{ $instructor->second_name }} {{ $instructor->name }} {{ $instructor->surname }}</option>
               @endforeach
           </select>

           <select name="year">
               <option value="">Выбрать год</option>
               @foreach($years as $year)
                   <option value="{{ $year->year }}">{{ $year->year }}</option>
               @endforeach

           </select>
           <select name="lessons">
               <option value="">Выбрать вид спорта</option>
               @foreach($lessons as $lesson)
                   <option value="{{ $lesson->lessons }}">{{ $lesson->lessons }}</option>
               @endforeach

           </select>

           <select name="months">
               <option value="">Выбрать месяц</option>
               <option value="Январь">Январь</option>
               <option value="Февраль">Февраль</option>
               <option value="Март">Март</option>
               <option value="Апрель">Апрель</option>
               <option value="Май">Май</option>
               <option value="Июнь">Июнь</option>
               <option value="Июль">Июль</option>
               <option value="Август">Август</option>
               <option value="Сентябрь">Сентябрь</option>
               <option value="Октябрь">Октябрь</option>
               <option value="Ноябрь">Ноябрь</option>
               <option value="Декабрь">Декабрь</option>
           </select>

           <input type="submit" value="Фильтровать" class="bg-blue-600 text-white rounded-[5px]">
       </form>

   </div>
    <div class="mt-[30px]">
        <h2 class="text-2xl font-bold">Суммарная статистика1</h2>
        <div  class="mt-[30px]">
            <table class="section_result">
                <tbody>
                <tr class="header">
                    <th rowspan="2"   class="border-solid border border-black p-2">ВСЕГО ЗАНИМАВШИХСЯ</th>
                    <th rowspan="2"   class="border-solid border border-black p-2">платно часов</th>
                    <th rowspan="2"   class="border-solid border border-black p-2">бесплатно часов</th>
                    <th rowspan="2"   class="border-solid border border-black p-2">всего часов</th>
                    <th colspan="4"   class="border-solid border border-black p-2">общее число занимавшися</th>
                    <th colspan="2"   class="border-solid border border-black p-2">От 3 до 18 лет</th>
                    <th colspan="2"   class="border-solid border border-black p-2">От 19 до 55 лет</th>
                    <th colspan="2"   class="border-solid border border-black p-2">Старше 55 лет</th>
                    <th colspan="2"   class="border-solid border border-black p-2">Нет возраста</th>
                </tr>
                <tr class="header">
                    <th  class="border-solid border border-black p-2">От 3 до 18 лет</th>
                    <th  class="border-solid border border-black p-2">От 19 до 55 лет</th>
                    <th  class="border-solid border border-black p-2">Старше 55 лет</th>
                    <th  class="border-solid border border-black p-2">Нет возраста</th>
                    <td  class="border-solid border border-black p-2">платно</td>
                    <td  class="border-solid border border-black p-2">бесплатно</td>
                    <td  class="border-solid border border-black p-2">платно</td>
                    <td  class="border-solid border border-black p-2">бесплатно</td>
                    <td  class="border-solid border border-black p-2">платно</td>
                    <td  class="border-solid border border-black p-2">бесплатно</td>
                    <td  class="border-solid border border-black p-2">платно</td>
                    <td  class="border-solid border border-black p-2">бесплатно</td>
                </tr>
                <tr>

                    <td class="border-solid border border-black p-2">{{ $statistics['membersAll'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['payLessons'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['freeLessons'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['allLessons'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['members318'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['members1955'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['members55'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['membersNo'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['members318pay'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['members318free'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['members1955pay'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['members1955free'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['members55pay'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['members55free'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['membersNopay'] }}</td>
                    <td  class="border-solid border border-black p-2">{{ $statistics['members55free'] }}</td>
                </tr>
                </tbody>
            </table>

        </div>
   @if(count($reports) != 0)
       <div class="mt-[30px]">
           <h2 class="text-2xl font-bold">Отчеты</h2>
       </div>
       <table class="w-full my-[50px]">
           <tbody><tr>
               <th  class="border-solid border border-black p-2">номер</th>
               <th  class="border-solid border border-black p-2">Отчетный месяц</th>
               <th  class="border-solid border border-black p-2">Отчетный год</th>
               <th  class="border-solid border border-black p-2">программа занятий</th>
               <th class="border-solid border border-black p-2">Центр</th>
               <th class="border-solid border border-black p-2">Участник</th>
               <th class="border-solid border border-black p-2">Болезнь </th>
               <th class="border-solid border border-black p-2">инструктор</th>
               <th class="border-solid border border-black p-2"> за счет каких грантов/субсидий</th>
               <th class="border-solid border border-black p-2">возрастная группа</th>
               <th class="border-solid border border-black p-2">всего часов</th>
               <th class="border-solid border border-black p-2">платно часов</th>
               <th class="border-solid border border-black p-2">бесплатно часов</th>
               <th class="border-solid border border-black p-2">Действия</th>
           </tr>
           @foreach ($reports as $key => $report)

               <tr class="border-solid border border-black p-2">
                   <td class="border-solid border border-black p-2">{{$key + 1}}</td>
                   <td class="border-solid border border-black p-2">{{ $report->months }}</td>
                   <td class="border-solid border border-black p-2">{{ $report->year }}</td>
                   <td class="border-solid border border-black p-2">{{ $report->lessons }}</td>
                   <td class="border-solid border border-black p-2">{{ $report->center->name }}</td>
                   <td class="border-solid border border-black p-2">{{ $report->member->fullname }}</td>
                   <td class="border-solid border border-black p-2">{{ $report->member->diagnosis }}</td>
                   <td class="border-solid border border-black p-2">{{ $report->instructor->second_name }} {{ $report->instructor->name}} {{  $report->instructor->surname }}</td>
                   <td class="border-solid border border-black p-2">{{ $report->grants }}</td>
                   <td class="border-solid border border-black p-2">

                       @php
                           $birthday = new DateTime($report->member->birthday);
                              $interval = $birthday->diff(new DateTime);

                       @endphp
                       @if($interval->y >= 3 && $interval->y <= 18 )
                           От 3 до 18 лет
                       @elseif($interval->y >= 19 && $interval->y <= 55)
                           От 19 до 55 лет
                       @elseif($interval->y > 55)
                           Старше 55 лет
                       @elseif($interval->y <= 0)
                           Нет возраста
                       @endif


                   </td>
                   <td class="border-solid border border-black p-2">{{ (int)$report->pay_lessons + (int)$report->free_lessons  }} </td>
                   <td class="border-solid border border-black p-2">{{ $report->pay_lessons }}</td>
                   <td class="border-solid border border-black p-2">{{ $report->free_lessons }}</td>
                   <td class="border-solid border border-black p-2">
                       <div class="flex items-center justify-between">
                           <a href="{{ route('reports.edit', $report->id)  }}" class="p-2">
                               <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
                                   <path stroke-linecap="round" stroke-linejoin="round" d="M16.862 4.487l1.687-1.688a1.875 1.875 0 112.652 2.652L6.832 19.82a4.5 4.5 0 01-1.897 1.13l-2.685.8.8-2.685a4.5 4.5 0 011.13-1.897L16.863 4.487zm0 0L19.5 7.125" />
                               </svg>
                           </a>
                           <form action="{{ route('reports.delete', $report->id)  }}" method="POST">
                               @csrf
                               @method('DELETE')
                               <button type="submit" class="p-2">
                                   <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
                                       <path stroke-linecap="round" stroke-linejoin="round" d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0" />
                                   </svg>
                               </button>
                           </form>
                       </div>
                   </td>
               </tr>
           @endforeach


           </tbody></table>
   @else
       <h1 class="text-2xl font-bold mt-[50px]">Данные не найдены</h1>
   @endif





@endsection
